#include <iostream>
#include <pcl/io/obj_io.h>
#include <pcl/io/vtk_lib_io.h>
#include <pcl/PolygonMesh.h>
#include <pcl/visualization/pcl_visualizer.h>
#include <string>

int main (int argc, char** argv)
{

  if(argc <= 1)
  {
	  cout<<"Specify a plain obj mesh (without materials).";
	  return 0;
  }
	 
  std::string strFileName(argv[1]);

  pcl::PolygonMesh sMesh1,sMesh2;
  //load
  pcl::io::loadPolygonFileOBJ(strFileName.c_str(),sMesh1); // in debug mode of vs2010, the target file should locate at "build" folder  
  //visualization
  pcl::visualization::PCLVisualizer viewer = pcl::visualization::PCLVisualizer ("3D Viewer"); 
  viewer.setBackgroundColor (0, 0, 0); 
  viewer.addPolygonMesh(sMesh1); 
  
  //save
  if (argc == 3)
  {
	  std::string strFileName2(argv[2]);

	  pcl::io::loadPolygonFileOBJ(strFileName2.c_str(),sMesh2); // in debug mode of vs2010, the target file should locate at "build" folder  
	  viewer.addPolygonMesh(sMesh2,strFileName2);
	  //store obj file
	  //std::string strSaveFileName(argv[2]);
	  //cout << strSaveFileName.c_str();
	  //pcl::io::saveOBJFile(strSaveFileName.c_str(),sMesh);
  }

  while (!viewer.wasStopped ()) 
  { 
	  viewer.spinOnce (100); 
	  //boost::this_thread::sleep (boost::posix_time::microseconds (100000)); 
  } 
  return (0);
}
